<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户id" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="邀请人" prop="parentUserId">-->
<!--        <el-input-->
<!--          v-model="queryParams.parentUserId"-->
<!--          placeholder="请输入邀请人"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户名" prop="username">-->
<!--        <el-input-->
<!--          v-model="queryParams.username"-->
<!--          placeholder="请输入用户名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="昵称" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="密码" prop="password">-->
<!--        <el-input-->
<!--          v-model="queryParams.password"-->
<!--          placeholder="请输入密码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="密码盐" prop="salt">-->
<!--        <el-input-->
<!--          v-model="queryParams.salt"-->
<!--          placeholder="请输入密码盐"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="电子邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入电子邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="头像" prop="avatar">-->
<!--        <el-input-->
<!--          v-model="queryParams.avatar"-->
<!--          placeholder="请输入头像"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生日" prop="birthday">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.birthday"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择生日">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="格言" prop="bio">-->
<!--        <el-input-->
<!--          v-model="queryParams.bio"-->
<!--          placeholder="请输入格言"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="余额" prop="money">-->
<!--        <el-input-->
<!--          v-model="queryParams.money"-->
<!--          placeholder="请输入余额"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="积分" prop="score">-->
<!--        <el-input-->
<!--          v-model="queryParams.score"-->
<!--          placeholder="请输入积分"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="剧场积分" prop="usable">-->
<!--        <el-input-->
<!--          v-model="queryParams.usable"-->
<!--          placeholder="请输入剧场积分"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="上次登录时间" prop="prevtime">-->
<!--        <el-input-->
<!--          v-model="queryParams.prevtime"-->
<!--          placeholder="请输入上次登录时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="登录时间" prop="logintime">-->
<!--        <el-input-->
<!--          v-model="queryParams.logintime"-->
<!--          placeholder="请输入登录时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="登录IP" prop="loginip">-->
<!--        <el-input-->
<!--          v-model="queryParams.loginip"-->
<!--          placeholder="请输入登录IP"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加入IP" prop="joinip">-->
<!--        <el-input-->
<!--          v-model="queryParams.joinip"-->
<!--          placeholder="请输入加入IP"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加入时间" prop="jointime">-->
<!--        <el-input-->
<!--          v-model="queryParams.jointime"-->
<!--          placeholder="请输入加入时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建时间" prop="createtime">-->
<!--        <el-input-->
<!--          v-model="queryParams.createtime"-->
<!--          placeholder="请输入创建时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="更新时间" prop="updatetime">-->
<!--        <el-input-->
<!--          v-model="queryParams.updatetime"-->
<!--          placeholder="请输入更新时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="VIP到期时间" prop="vipExpiretime">-->
<!--        <el-input-->
<!--          v-model="queryParams.vipExpiretime"-->
<!--          placeholder="请输入VIP到期时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="Token" prop="token">-->
<!--        <el-input-->
<!--          v-model="queryParams.token"-->
<!--          placeholder="请输入Token"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="验证" prop="verification">-->
<!--        <el-input-->
<!--          v-model="queryParams.verification"-->
<!--          placeholder="请输入验证"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
<!--      <el-table-column label="站点" align="center" prop="siteId" />-->
<!--      <el-table-column label="组别ID" align="center" prop="groupId" />-->
<!--      <el-table-column label="邀请人" align="center" prop="parentUserId" />-->
      <el-table-column label="头像" align="center" prop="avatar" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" :width="30" :height="30"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="用户名" align="center" prop="username" />-->
      <el-table-column label="昵称" align="center" prop="nickname" />
<!--      <el-table-column label="密码" align="center" prop="password" />-->
<!--      <el-table-column label="密码盐" align="center" prop="salt" />-->
      <el-table-column label="电子邮箱" align="center" prop="email" width="300px" />
      <el-table-column label="手机号" align="center" prop="mobile" />
<!--      <el-table-column label="等级" align="center" prop="level" />-->
<!--      <el-table-column label="性别" align="center" prop="gender" />-->
<!--      <el-table-column label="生日" align="center" prop="birthday" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="格言" align="center" prop="bio" />-->
      <el-table-column label="余额" align="center" prop="money" />
<!--      <el-table-column label="积分" align="center" prop="score" />-->
      <el-table-column label="剧场积分" align="center" prop="usable" />
<!--      <el-table-column label="连续登录天数" align="center" prop="successions" />-->
<!--      <el-table-column label="最大连续登录天数" align="center" prop="maxsuccessions" />-->
<!--      <el-table-column label="上次登录时间" align="center" prop="prevtime" />-->
      <el-table-column label="登录时间" align="center" prop="logintime" width="160px" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.logintime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="登录IP" align="center" prop="loginip" />-->
<!--      <el-table-column label="失败次数" align="center" prop="loginfailure" />-->
<!--      <el-table-column label="加入IP" align="center" prop="joinip" />-->
      <el-table-column label="加入时间" align="center" prop="jointime" width="160px" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jointime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="创建时间" align="center" prop="createtime" />-->
<!--      <el-table-column label="更新时间" align="center" prop="updatetime" />-->
<!--      <el-table-column label="VIP到期时间" align="center" prop="vipExpiretime" />-->
<!--      <el-table-column label="Token" align="center" prop="token" />-->
<!--      <el-table-column label="模式:guest=游客,user=用户" align="center" prop="mode" />-->
<!--      <el-table-column label="状态" align="center" prop="status" />-->
<!--      <el-table-column label="验证" align="center" prop="verification" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
              <!--        <el-form-item label="站点" prop="siteId">-->
              <!--          <el-input v-model="form.siteId" placeholder="请输入站点" />-->
              <!--        </el-form-item>-->
              <!--        <el-form-item label="用户名" prop="username">-->
              <!--          <el-input v-model="form.username" placeholder="请输入用户名" />-->
              <!--        </el-form-item>-->
              <el-form-item label="昵称" prop="nickname">
                <el-input v-model="form.nickname" placeholder="请输入昵称" />
              </el-form-item>
              <el-form-item label="密码" prop="password">
                <el-input v-model="form.password" placeholder="不修改请留空" />
              </el-form-item>
              <!--        <el-form-item label="密码盐" prop="salt">-->
              <!--          <el-input v-model="form.salt" placeholder="请输入密码盐" />-->
              <!--        </el-form-item>-->
              <el-form-item label="电子邮箱" prop="email">
                <el-input v-model="form.email" placeholder="请输入电子邮箱" />
              </el-form-item>
              <el-form-item label="手机号" prop="mobile">
                <el-input v-model="form.mobile" placeholder="请输入手机号" />
              </el-form-item>
              <!--        <el-form-item label="头像" prop="avatar">-->
              <!--          <el-input v-model="form.avatar" placeholder="请输入头像" />-->
              <!--        </el-form-item>-->
              <!--        <el-form-item label="生日" prop="birthday">-->
              <!--          <el-date-picker clearable-->
              <!--            v-model="form.birthday"-->
              <!--            type="date"-->
              <!--            value-format="yyyy-MM-dd"-->
              <!--            placeholder="请选择生日">-->
              <!--          </el-date-picker>-->
              <!--        </el-form-item>-->
              <!--        <el-form-item label="格言" prop="bio">-->
              <!--          <el-input v-model="form.bio" placeholder="请输入格言" />-->
              <!--        </el-form-item>-->
              <!--        <el-form-item label="积分" prop="score">-->
              <!--          <el-input v-model="form.score" placeholder="请输入积分" />-->
              <!--        </el-form-item>-->
              <el-form-item label="上次登录时间" prop="prevtime">
                <div>{{ parseTime(form.prevtime, '{y}-{m}-{d} {h}:{i}:{s}') }}</div>
              </el-form-item>
            <el-form-item label="登录IP" prop="loginip">
              <div>{{ form.loginip }}</div>
            </el-form-item>
              <el-form-item label="登录时间" prop="logintime">
                <div>{{ parseTime(form.logintime, '{y}-{m}-{d} {h}:{i}:{s}') }}</div>
              </el-form-item>
              <!--        <el-form-item label="Token" prop="token">-->
              <!--          <el-input v-model="form.token" placeholder="请输入Token" />-->
              <!--        </el-form-item>-->
              <!--        <el-form-item label="验证" prop="verification">-->
              <!--          <el-input v-model="form.verification" placeholder="请输入验证" />-->
              <!--        </el-form-item>-->
          </el-col>
          <el-col :span="12">
            <el-form-item label="邀请人" prop="parentUserId">
              <div v-if="form.parentUserId != null && form.parentUserId != ''">
                <el-col>{{ form.parentUserId }}</el-col>
              </div>
              <div v-else>
                <el-col :span="22">暂无</el-col>
                <el-col :span="2">
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleParentUser"
                  >设置</el-button>
                </el-col>
              </div>
            </el-form-item>
            <el-form-item label="余额" prop="money">
              <el-col :span="22">
                <el-input v-model="form.money" readonly placeholder="请输入余额" />
              </el-col>
              <el-col :span="2">
                <el-button
                  size="mini"
                  type="text"
                  @click="setMoney"
                >充值</el-button>
              </el-col>
            </el-form-item>
            <el-form-item label="剧场积分" prop="usable">
              <el-col :span="22">
                <el-input v-model="form.usable" readonly placeholder="请输入剧场积分" />
              </el-col>
<!--              <el-col :span="4">-->
<!--                <el-button-->
<!--                  size="mini"-->
<!--                  type="text"-->
<!--                  @click="setUsable"-->
<!--                >设置</el-button>-->
<!--              </el-col>-->
              <el-col :span="2">
                <el-button
                  size="mini"
                  type="text"
                  @click="rechargeUsable"
                >充值</el-button>
              </el-col>
            </el-form-item>
            <el-form-item label="VIP" prop="vipExpiretime">
              <el-date-picker clearable
                              v-model="form.vipExpiretime"
                              type="date"
                              value-format="timestamp"
                              placeholder="请选择VIP到期时间"
                              @change="handleVipExpiretimeChange"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="分销商" prop="resellerExpiretime">
              <el-col :span="22">
                <span>{{ form.resellerName }}</span>
                <span v-if="form.resellerExpiretime != null && form.resellerExpiretime != 0">({{ parseTime(form.resellerExpiretime, '{y}-{m}-{d} {h}:{i}:{s}') }})</span>
                <span v-else-if="form.resellerExpiretime != null && form.resellerExpiretime == 0">（ 永久 ）</span>
              </el-col>
              <el-col :span="2">
                <el-button
                  size="mini"
                  type="text"
                  @click="setReseller"
                >设置</el-button>
              </el-col>
            </el-form-item>
            <el-form-item label="加入IP" prop="joinip">
              <div>{{ form.joinip }}</div>
            </el-form-item>
            <el-form-item label="加入时间" prop="jointime">
              <div>{{ parseTime(form.jointime, '{y}-{m}-{d} {h}:{i}:{s}') }}</div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="推荐人" :visible.sync="openParent" width="1200px" append-to-body>
      <el-table v-loading="parentLoading" :data="userList" highlight-current-row @current-change="handleCurrentChange">
        <el-table-column label="头像" align="center" prop="avatar" >
          <template slot-scope="scope">
            <image-preview :src="scope.row.image" :width="30" :height="30"/>
          </template>
        </el-table-column>
        <el-table-column label="用户名" align="center" prop="id" />
        <el-table-column label="昵称" align="center" prop="nickname" />
        <el-table-column label="电子邮箱" align="center" prop="email" width="300px" />
        <el-table-column label="手机号" align="center" prop="mobile" />
      </el-table>

      <pagination
        v-show="parentTotal>0"
        :total="parentTotal"
        :page.sync="parentPageNum"
        :limit.sync="parentPageSize"
        @pagination="handleParentUser"
      />

      <div slot="footer" class="dialog-footer">
        <el-button @click="parentCancel">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="充值钱包余额" :visible.sync="openRechargeMoney" width="300px" append-to-body>
      <el-form ref="form" :model="moneyForm" label-width="100px">
        <el-form-item label="充值余额" prop="usable">
          <el-input v-model="moneyForm.money" placeholder="请输入充值余额" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="rechargeUserMoney">确 定</el-button>
        <el-button @click="rechargeUserMoneyCancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="充值积分" :visible.sync="openRechargeUsable" width="300px" append-to-body>
      <el-form ref="form" :model="rechargeForm" label-width="100px">
        <el-form-item label="充值积分" prop="usable">
          <el-input v-model="rechargeForm.usable" placeholder="请输入充值积分" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="rechargeUserUsable">确 定</el-button>
        <el-button @click="rechargeUserUsableCancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="分销套餐" :visible.sync="openReseller" width="200px" append-to-body>
      <el-select v-model="resellerThali" placeholder="请选择">
        <el-option
          v-for="(item, index) in resellerList"
          :key="item.id"
          :label="item.name"
          :value="item.id">
        </el-option>
      </el-select>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitReseller">确 定</el-button>
        <el-button @click="resellerCancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listUser, getUser, delUser, addUser, updateUser, parentUser, rechargeUserUsable, selectVsUserByInfo, rechargeUserMoney } from "@/api/user/user";
import { listReseller, submitReseller } from "@/api/reseller/reseller";

export default {
  name: "User",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        siteId: null,
        groupId: null,
        parentUserId: null,
        username: null,
        nickname: null,
        password: null,
        salt: null,
        email: null,
        mobile: null,
        avatar: null,
        level: null,
        gender: null,
        birthday: null,
        bio: null,
        money: null,
        score: null,
        usable: null,
        successions: null,
        maxsuccessions: null,
        prevtime: null,
        logintime: null,
        loginip: null,
        loginfailure: null,
        joinip: null,
        jointime: null,
        createtime: null,
        updatetime: null,
        vipExpiretime: null,
        token: null,
        mode: null,
        status: null,
        verification: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // money: [
        //   { required: true, message: "余额不能为空", trigger: "blur" }
        // ],
        // score: [
        //   { required: true, message: "积分不能为空", trigger: "blur" }
        // ],
        // usable: [
        //   { required: true, message: "剧场积分不能为空", trigger: "blur" }
        // ],
        // successions: [
        //   { required: true, message: "连续登录天数不能为空", trigger: "blur" }
        // ],
        // maxsuccessions: [
        //   { required: true, message: "最大连续登录天数不能为空", trigger: "blur" }
        // ],
        // loginfailure: [
        //   { required: true, message: "失败次数不能为空", trigger: "blur" }
        // ],
      },
      openParent: false,
      parentList: [],
      parentLoading: false,
      parentTotal: 0,
      parentPageNum: 1,
      parentPageSize: 10,
      usableList: [],
      openUsable: false,
      usableThali: '',
      openRechargeUsable: false,
      rechargeForm: {},
      vipList: [],
      openVip: false,
      resellerList: [],
      openReseller: false,
      vipThali: '',
      resellerThali: '',
      openRechargeMoney: false,
      moneyForm: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会员列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        siteId: null,
        groupId: null,
        parentUserId: null,
        username: null,
        nickname: null,
        password: null,
        salt: null,
        email: null,
        mobile: null,
        avatar: null,
        level: null,
        gender: null,
        birthday: null,
        bio: null,
        money: null,
        score: null,
        usable: null,
        successions: null,
        maxsuccessions: null,
        prevtime: null,
        logintime: null,
        loginip: null,
        loginfailure: null,
        joinip: null,
        jointime: null,
        createtime: null,
        updatetime: null,
        vipExpiretime: null,
        token: null,
        mode: null,
        status: null,
        verification: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      let params = {
        id: row.id || this.ids
      }
      selectVsUserByInfo(params).then(response => {
        this.form = response.data;
        this.form.password = null;
        this.open = true;
        this.title = "修改会员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除会员编号为"' + ids + '"的数据项？').then(function() {
        return delUser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    },
    handleParentUser() {
      let params = {
        id: this.form.id,
        parentUserId: this.form.parentUserId,
        pageNum: this.parentPageNum,
        pageSize: this.parentPageSize,
        createtime: null,
        updatetime: null,
      }
      this.parentLoading = true;
      parentUser(params).then(response => {
        this.parentList = response.rows;
        this.parentTotal = response.total;
        this.openParent = true;
        this.parentLoading = false;
      });
    },
    // 取消按钮
    parentCancel() {
      this.openParent = false;
      this.parentPageNum = 1;
      this.parentPageSize = 10;
      this.parentList = [];
      this.parentTotal = 0;
    },
    handleCurrentChange(val) {
      let params = {
        id: this.form.id,
        parentUserId: val.id,
        updatetime: new Date().getTime()
      }
      updateUser(params).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.openParent = false;
        this.form.parentUserId = val.id
      });
    },
    setMoney() {
      this.openRechargeMoney = true;
    },
    rechargeUserMoney() {
      let params = {
        id: this.form.id,
        money: this.moneyForm.money,
      }
      rechargeUserMoney(params).then(response => {
        this.$modal.msgSuccess("充值成功！");
        if (!this.form.money) {
          this.form.money = this.moneyForm.money
        } else {
          this.form.money = Number(this.form.money) + this.moneyForm.money
        }
        this.rechargeUserMoneyCancel();
      })
    },
    rechargeUserMoneyCancel() {
      this.openRechargeMoney = false;
      this.rechargeForm = {};
    },
    rechargeUsable() {
      this.openRechargeUsable = true;
    },
    rechargeUserUsable() {
      let params = {
        id: this.form.id,
        usable: this.rechargeForm.usable,
      }
      rechargeUserUsable(params).then(response => {
        this.$modal.msgSuccess("充值成功！");
        if (!this.form.usable) {
          this.form.usable = this.rechargeForm.usable
        } else {
          this.form.usable = Number(this.form.usable) + Number(this.rechargeForm.usable)
        }
        this.rechargeUserUsableCancel();
      })
    },
    rechargeUserUsableCancel() {
      this.openRechargeUsable = false;
      this.rechargeForm = {};
    },
    handleVipExpiretimeChange() {
      let params = {
        id: this.form.id,
        vipExpiretime: this.form.vipExpiretime,
      }
      updateUser(params).then(response => {
        this.$modal.msgSuccess("VIP充值成功");
      })
    },
    setReseller() {
      let params = {
        pageNum: 1,
        pageSize: 10000,
      }
      listReseller(params).then(response => {
        this.resellerList = response.rows;
        this.openReseller = true;
      });
    },
    submitReseller() {
      let params = {
        id: this.resellerThali,
        userId: this.form.id,
      }
      submitReseller(params).then(response => {
        this.$modal.msgSuccess("充值成功！");
        this.form.resellerId = this.resellerList[this.resellerThali].id
        this.resellerCancel();
      })
    },
    resellerCancel() {
      this.openReseller = false;
    },
  }
};
</script>
